package com.lanou3g.ptp.api.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import com.lanou3g.ptp.attendance.service.AttendanceService;
import com.lanou3g.ptp.entity.Attendance;
import com.lanou3g.utils.PtpResult;
import com.lanou3g.utils.PtpResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Api("签到接口")
@RestController
public class AttentController {

    @Reference
    private AttendanceService attendanceService;

    @ApiOperation("通过ID获取签到信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "学生Id")
    })
    @GetMapping("/attendances/attendance/{studentId}")
    public PtpResult findByStudentId(@PathVariable long studentId){

        System.out.println(studentId);
       List<Attendance> attendances= attendanceService.findByStudentId(studentId);
        return PtpResultUtils.ok(attendances);

    }

    @ApiOperation("qqq")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "学生Id")
    })
    @PostMapping("/attendances/{studentId}")
    public void addAttentInfor(Attendance attendance) {
            attendanceService.addAttentInfor(attendance);

    }

    @ApiOperation("查询所有签到信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页数"),
            @ApiImplicitParam(name = "size", value = "显示条数")
    })
    @GetMapping("/attendances")
    public PtpResult findAll(@RequestParam(value = "page", defaultValue = "1") Integer page,
                             @RequestParam(value = "size", defaultValue = "5")Integer size){
        PageInfo<Attendance> all1 = attendanceService.findAll(page, size);
        return PtpResultUtils.ok(all1);
    }

    @ApiOperation("通过ID获取该学生的签到日期")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "taskId")
    })
    @GetMapping("/attendances/sign_time/{studentId}")
    public PtpResult findSignTime(@PathVariable long studentId,@PathVariable String signtime){
        List<Attendance> signTime = attendanceService.findSignTime(studentId,signtime);
        return PtpResultUtils.ok(signTime);
    }

    @ApiOperation("")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "", value = "")
    })
    @GetMapping("/attendances/task/{studentId}/{taskId}")
    public PtpResult fingStudentTask(@PathVariable long studentId,@PathVariable long taskId){

        List<Attendance> studentTask = attendanceService.findStudentTask(studentId, taskId);
        return PtpResultUtils.ok(studentTask);
    }

    @GetMapping("/attendances/task/{taskId}")
    public PtpResult findBytaskId(@PathVariable long taskId){
        List<Attendance> byTaskId = attendanceService.findByTaskId(taskId);
        return PtpResultUtils.ok(byTaskId);
    }

    @ApiOperation("签到")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "studentId", value = "tokenId"),
            @ApiImplicitParam(name = "taskId", value = "任务Id"),
            @ApiImplicitParam(name = "longitude", value = "经度"),
            @ApiImplicitParam(name = "latitude", value = "纬度"),
//            @ApiImplicitParam(name = "signTime", value = "签到时间"),
//            @ApiImplicitParam(name = "status", value = "签到状态"),
//            @ApiImplicitParam(name = "createTime", value = "创建时间"),
//            @ApiImplicitParam(name = "updateTime", value = "更改时间")
    })
    @PostMapping("/attendance")
    public PtpResult addAttendance(String token,Long
                                   taskId,Long longitude,Long latitude){
        return PtpResultUtils.ok();
    }

}
